/**
 * @description: 钉钉授权登录及用户信息获取
 * @version: 0.0.1
 * @author: z..
 * @Date: 2023-06-12 18:16:39
 */

import { Inject, Controller, Post, Body, Get } from '@midwayjs/core';
import { DingtalkRobotService } from '../service/dingtalk.robot.service';
import { GetAlarmPageDTO, InsertAlarmDTO, UpdateAlarmDTO, UpdateAlarmStatusDTO, SendAlarmMsgDTO } from '../dto/dingtalk.robot';
import { IdDTO } from "../dto/common"
import { Context } from '@midwayjs/koa';

@Controller('/api/v1/robot/alarm')
export class DingtalkRobot {
  @Inject()
  ctx: Context;

  @Inject()
  DingtalkRobotService: DingtalkRobotService;

  /**
    * @summary 钉钉机器人回调地址
    * @description 钉钉机器人回调地址
    * @router post /api/v1/dingtalk/robot/callback
    * @request body orderName  *body
    * @response 200 baseResponse 返回结果
    */
  @Post("/callback")
  async robotCallback(): Promise<any> {
    const {
      ctx
    } = this;
    return ctx.unionId;
  }

  /**
   * @summary 任务通知分页查询
   * @description 任务通知分页查询
   * @router post /api/v1/robot/alarm/getAlarmPage
   * @response 200 baseResponse 返回结果
   */
  @Post("/getAlarmPage")
  async getAlarmPage(@Body() options: GetAlarmPageDTO): Promise<any> {
    return await this.DingtalkRobotService.getAlarmPage(options);
  }

  /**
   * @summary 新增任务通知
   * @description 新增任务通知
   * @router post /api/v1/robot/alarm/insertAlarm
   * @response 200 baseResponse 返回结果
   */
  @Post("/insertAlarm")
  async insertAlarm(@Body() options: InsertAlarmDTO): Promise<any> {
    return await this.DingtalkRobotService.insertAlarm(options);
  }

  /**
   * @summary 更新任务通知
   * @description 更新任务通知
   * @router post /api/v1/robot/alarm/updateAlarm
   * @response 200 baseResponse 返回结果
   */
  @Post("/updateAlarm")
  async updateAlarm(@Body() options: UpdateAlarmDTO): Promise<any> {
    return await this.DingtalkRobotService.updateAlarm(options);
  }

  /**
   * @summary 删除任务通知
   * @description 删除任务通知
   * @router post /api/v1/robot/alarm/delAlarm
   * @response 200 baseResponse 返回结果
   */
  @Post("/delAlarm")
  async delAlarm(@Body() options: IdDTO): Promise<any> {
    return await this.DingtalkRobotService.delAlarm(options);
  }

  /**
   * @summary 查询任务通知
   * @description 查询任务通知
   * @router post /api/v1/robot/alarm/getAlarmById
   * @response 200 baseResponse 返回结果
   */
  @Post("/getAlarmById")
  async getAlarmById(@Body() options: IdDTO): Promise<any> {
    return await this.DingtalkRobotService.getAlarmById(options);
  }

  /**
   * @summary 修改任务通知状态
   * @description 修改任务通知状态
   * @router post /api/v1/robot/alarm/updateAlarmStatus
   * @response 200 baseResponse 返回结果
   */
  @Post("/updateAlarmStatus")
  async updateAlarmStatus(@Body() options: UpdateAlarmStatusDTO): Promise<any> {
    return await this.DingtalkRobotService.updateAlarmStatus(options);
  }

  /**
   * @summary 通知任务开启和关闭时发送消息
   * @description 通知任务开启和关闭时发送消息
   * @router post /api/v1/robot/alarm/sendMsg
   * @response 200 baseResponse 返回结果
   */
  @Post("/sendMsg")
  async sendAlarmMsg(@Body() options: SendAlarmMsgDTO): Promise<any> {
    return await this.DingtalkRobotService.sendAlarmMsg(options);
  }

  /**
   * @summary 定时任务触发
   * @description 定时任务触发
   * @router get /api/v1/robot/alarm/scheduleTasks
   * @response 200 baseResponse 返回结果
   */
  @Get('/scheduleTasks')
  async scheduleTasks(): Promise<any> {
    return await this.DingtalkRobotService.scheduleTasks();
  }

}
